package net.tensor.tensorprovider.controller;

import net.tensor.tensorprovider.config.ProviderService;
import net.tensor.tensorprovider.exception.ResultBody;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: lockie
 * @Date: 2020/4/21 11:17
 * @Description:
 */
@RestController
@RequestMapping("/mq")
public class MQProducerController {
    public static final Logger LOGGER = LoggerFactory.getLogger(MQProducerController.class);

    @Autowired
    ProviderService providerService;

    /**
     * 发送简单的MQ消息
     * @param msg
     * @return
     */
    @GetMapping("/send/{msg}")
    public ResultBody send(@PathVariable(name = "msg") String msg) {
        ResultBody resultBody=new ResultBody();
        if (StringUtils.isEmpty(msg)) {
            resultBody.setCode("200");
            resultBody.setMessage("成功");
            return resultBody;
        }
        LOGGER.info("发送MQ消息内容：" + msg);
        // 默认3秒超时
        Boolean sendResult = providerService.send(msg);
        LOGGER.info("消息发送响应：" + sendResult);
        resultBody.setCode("200");
        resultBody.setMessage("成功");
        resultBody.setResult("消息发送响应：" + sendResult);
        return resultBody;
    }

}